package com.java.jwt.controller;

import com.java.jwt.common.CommonResult;
import com.java.jwt.common.PageUtils;
import com.java.jwt.entity.BrandEntity;
import com.java.jwt.servcie.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 品牌
 *
 * @author jiangli
 * @email 31346337@qq.com
 * @date 2020-06-14 20:41:07
 */
@Api(tags = "品牌管理")
@RestController
@RequestMapping("product/brand")
public class BrandController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @ApiOperation("查询品牌列表")
    @RequestMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params) {
        PageUtils page = brandService.queryPage(params);
        logger.info("INFO===/product/brand/list查询成功===");
        logger.debug("DEBUG===/product/brand/list查询成功===");
        return CommonResult.success(page);
    }


    /**
     * 信息
     */
    @ApiOperation("查询单个品牌信息")
    @RequestMapping("/info/{brandId}")
    public CommonResult info(@PathVariable("brandId") Long brandId) {
        BrandEntity brand = brandService.getById(brandId);

        return CommonResult.success(brand);
    }

    /**
     * 保存
     */
    @ApiOperation("新增单个品牌信息")
    @RequestMapping("/save")
    public CommonResult save(@RequestBody BrandEntity brand/*,BindingResult result*/) {
        brandService.save(brand);
        return CommonResult.success(null);
    }


    /**
     * 修改
     */
    @ApiOperation("修改单个品牌信息")
    @RequestMapping("/update/status")
    public CommonResult updateStatus(@RequestBody BrandEntity brand) {
        brandService.updateById(brand);

        return CommonResult.success(null);
    }

    /**
     * 删除
     */
    @ApiOperation("批量删除品牌信息")
    @RequestMapping("/delete")
    public CommonResult delete(@RequestBody Long[] brandIds) {
        brandService.removeByIds(Arrays.asList(brandIds));

        return CommonResult.success(null);
    }

}
